#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <algorithm>
using namespace std;

string intToRoman(int num){
    string value1="IXCM";
    string value2="VLD";
    string result;
    short last=0,i=0;
    while(num!=0){
        last=num%10;
        num=num/10;
        switch(last){
            case 1:result.insert(0,string(1,value1[i]));break;
            case 2:result.insert(0,string(2,value1[i]));break;
            case 3:result.insert(0,string(3,value1[i]));break;
            case 4:result.insert(0,value1.substr(i,1)+value2.substr(i,1));break;
            case 5:result.insert(0,value2.substr(i,1));break;
            case 6:result.insert(0,value2.substr(i,1)+value1.substr(i,1));break;
            case 7:result.insert(0,value2.substr(i,1)+string(2,value1[i]));break;
            case 8:result.insert(0,value2.substr(i,1)+string(3,value1[i]));break;
            case 9:result.insert(0,value1.substr(i,2));break;
        }
        i++;
    }
    return result;
}

string intToRoman1(int num) {
    vector<int> value = { 1000,900,500,400,100,90,50,40,10,9,5,4,1 };
    vector<string> dic = { "M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I" };
    string str;
    int i = 0;
    while (num > 0 && i < dic.size()) {
        if (num >= value[i]) {
            str += dic[i];
            num -= value[i];
        }
        else
            i++;
    }
    return str;
}


int romanToInt(string s){
    int size = s.size();
    int result=0,i=0;
    while(i<size){
        if(s[i]=='I'&&s[i+1]=='V'){result+=4;i+=2;continue;}
        else if(s[i]=='I'&&s[i+1]=='X'){result+=9;i+=2;continue;}
        else if(s[i]=='X'&&s[i+1]=='L'){result+=40;i+=2;continue;}
        else if(s[i]=='X'&&s[i+1]=='C'){result+=90;i+=2;continue;}
        else if(s[i]=='C'&&s[i+1]=='D'){result+=400;i+=2;continue;}
        else if(s[i]=='C'&&s[i+1]=='M'){result+=900;i+=2;continue;}
        else {
            switch(s[i]){
                case 'I':result+=1;break;
                case 'V':result+=5;break;
                case 'X':result+=10;break;
                case 'L':result+=50;break;
                case 'C':result+=100;break;
                case 'D':result+=500;break;
                case 'M':result+=1000;break;
            }
        }
        i++;
    }
    return result;
}

int main(){

    cout<<romanToInt("MCMXCIV")<<endl;
    return 0;
}